#!/usr/bin/env bash
set -e

REGISTER_ADDRESS=10.120.26.8:5000
IMAGES=(forezp/service-hi forezp/eureka-server)


## mvn 加速

mkdir -p /root/.m2/
echo -e "<?xml version=\""1.0\"" encoding=\""UTF-8\""?><settings xmlns=\""http://maven.apache.org/SETTINGS/1.0.0\"" xmlns:xsi=\""http://www.w3.org/2001/XMLSchema-instance\"" xsi:schemaLocation=\""http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd\""><mirrors><mirror><id>alimaven</id><name>aliyun maven</name><url>http://maven.aliyun.com/nexus/content/groups/public/</url><mirrorOf>central</mirrorOf></mirror></mirrors></settings>" > /root/.m2/settings.xml


# build jar and image
mvn package -e  -DskipTest

## build image
docker-compose -f docker-compose.yml -f docker-compose-dev.yml build

## set docker register
mkdir -p "/etc/docker"
echo '{ "insecure-registries":["'$REGISTER_ADDRESS'"] }' > /etc/docker/daemon.json


for image in ${IMAGES[@]}
do
    tag_image=$REGISTER_ADDRESS/$image:`TZ=CST-8 date '+%Y%m%d-%H%M'`
    docker tag $image:latest $tag_image

    # push image
    echo "Push Image:" $tag_image " to repository..."
    docker push ${tag_image}

    docker rmi $tag_image && docker rmi $image:latest
done





